package com.xgry.bpm.api.base.meetingdata.controller;

import com.xgry.bpm.api.base.meetingdata.entity.MeetingData;
import com.xgry.bpm.api.base.meetingdata.form.MeetingDataForm;
import com.xgry.bpm.api.base.meetingdata.vo.MeetingDataVO;
import com.xgry.bpm.common.utils.EasyPoiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xgry.bpm.api.base.meetingdata.service.MeetingDataService;;

import java.util.List;

import org.springframework.http.HttpStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xgry.bpm.common.utils.Result;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * <p>
 * MeetingData前端控制器
 *
 * </p>
 *
 * @author admin
 * @since 2020-07-16
 */
@RestController
@Api(tags = "会议资料")
@RequestMapping("/meetingData")
public class MeetingDataController {
    @Autowired
    public MeetingDataService meetingDataService;

    /**
     * 保存单条
     *
     * @param param 保存参数
     * @return 是否添加成功
     */
    @ApiOperation(value = "保存", notes = "保存数据到MeetingData")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "${field.comment}", required = false),
            @ApiImplicitParam(paramType = "query", name = "content", value = "${field.comment}", required = false),
            @ApiImplicitParam(paramType = "query", name = "meetingsId", value = "${field.comment}", required = false),
            @ApiImplicitParam(paramType = "query", name = "name", value = "${field.comment}", required = false),
            @ApiImplicitParam(paramType = "query", name = "type", value = "${field.comment}", required = false),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "${field.comment}", required = false),
    })
    @RequestMapping(value = "/add.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result addMeetingData(@RequestBody MeetingDataForm param) {
        if (1 != meetingDataService.save(param)) {
            return Result.fail("保存失败");
        }
        return Result.success();
    }

    /**
     * 更新(根据主键id更新)
     *
     * @param param 修改参数
     * @return 是否更改成功
     */
    @ApiOperation(value = "更新数据", notes = "根据主键id更新MeetingData数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "content", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "meetingsId", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "name", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "type", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "${field.comment}", required = false, dataType = ""),
    })
    @RequestMapping(value = "/updateById.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result updateMeetingDataById(@RequestBody MeetingDataForm param) {
        if (1 != meetingDataService.updateById(param)) {
            return Result.fail("保存失败");
        }
        return Result.success();
    }


    /**
     * 删除(根据主键id删除)
     *
     * @param //主键id
     * @return 是否删除成功
     */
    @ApiOperation(value = "删除数据", notes = "根据主键id删除MeetingData数据")
    @ApiImplicitParam(paramType = "query", name = "", value = "Id", required = true, dataType = "String")
    @RequestMapping(value = "/deleteById.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @Transactional
    public Result deleteMeetingDataById(String[] ids) {
        int result = 0;
        for (String id : ids) {
            meetingDataService.deleteById(id);
            result++;
        }

        if (result > 0) {
            return Result.fail("删除失败！");
        }

        return Result.success("操作成功");
    }

    /**
     * 根据主键id查询单条
     *
     * @param // 主键id
     * @return 查询结果
     */
    @ApiOperation(value = "获取单条数据", notes = "根据主键id获取MeetingData数据")
    @ApiImplicitParam(paramType = "query", name = "", value = "Id", required = true, dataType = "String")
    @RequestMapping(value = "/getById.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result getMeetingDataById(@RequestParam(value = "Id") String id) {
        MeetingDataVO result = meetingDataService.selectById(id);
        if (null == result) {
            return Result.fail("无数据！");
        }
        return Result.success("操作成功", result);
    }

    /**
     * 查询全部
     *
     * @param //param 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "全部查询", notes = "查询MeetingData全部数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "content", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "meetingsId", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "name", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "type", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "${field.comment}", required = false, dataType = ""),
    })
    @RequestMapping(value = "/queryAll.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result getMeetingDataAll(@RequestBody MeetingDataForm param) {
        List<MeetingDataVO> result = meetingDataService.selectAll(param);
        if (CollectionUtils.isEmpty(result)) {
            return Result.fail("无数据！");
        }
        return Result.success("操作成功", result);
    }

    /**
     * 会议资料分页查询
     *
     * @param //param 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "会议资料分页查询", notes = "分页查询MeetingData全部数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "content", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "meetingsId", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "name", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "type", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "${field.comment}", required = false, dataType = ""),
    })
    @RequestMapping(value = "/findAllToData.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result getMeetingDataPage(@RequestBody MeetingDataForm param) {
        IPage<MeetingDataVO> result = meetingDataService.selectPageMeetingDataPage(param);
        if (CollectionUtils.isEmpty(result.getRecords())) {
            return Result.fail("无数据！");
        }
        return Result.convertIpageToSuccess(result);
    }

    /**
     * 会议纪要分页查询
     *
     * @param //param 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "会议纪要分页查询", notes = "分页查询MeetingData全部数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "content", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "meetingsId", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "name", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "type", value = "${field.comment}", required = false, dataType = ""),
            @ApiImplicitParam(paramType = "query", name = "userId", value = "${field.comment}", required = false, dataType = ""),
    })
    @RequestMapping(value = "/findAllToSummary.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result getfindAllToSummary(@RequestBody MeetingDataForm param) {
        IPage<MeetingDataVO> result = meetingDataService.selectPageToSummary(param);
        if (CollectionUtils.isEmpty(result.getRecords())) {
            return Result.fail("无数据！");
        }
        return Result.convertIpageToSuccess(result);
    }

    /**
     * Excel导入
     *
     * @param //param 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "Excel导入", notes = "导入全字段")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "", value = "", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "", value = "", required = false, dataType = "String")
    })
    @RequestMapping(value = "/importExcel.do", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result importExcel(@RequestParam MultipartFile file) throws Exception {
        List<MeetingData> list = EasyPoiUtils.importExcel(file, 0, 1, MeetingData.class);
        if (CollectionUtils.isEmpty(list)) {
            return Result.fail("无数据");
        }
        return Result.success();
    }

    /**
     * Excel导出
     *
     * @param //param 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "Excel导出", notes = "导出全字段")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "current", value = "页码", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "size", value = "每页条数", required = false, dataType = "String")

    })
    @RequestMapping(value = "/exportExcel.do", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public void exportExcel(HttpServletResponse response) throws Exception {
        List<MeetingData> result = meetingDataService.list();
        EasyPoiUtils.exportExcel(result, "列表", "报表", MeetingData.class, "明细报表.xls", response);

    }


}

